home *** CD-ROM | disk | FTP | other *** search
/ Giga Pack / Giga Pack CD1.iso / cards / bertha / progshop.c < prev    next >
Text File  |  1992-09-29  |  35KB  |  1,219 lines

  1. /**********************************************************************\
  2. *                                                                      *
  3. * PROGSHOP.C -- copyright 1992 Diana Gruber                            *
  4. *                                                                      *
  5. * This is the source code to the Bertha Slot game written by Diana     *
  6. * Gruber for The Programmer's Shop.  Source code is provided for       *
  7. * informational purposes only.  All function calls beginning with      *
  8. * "fg_" are Fastgraph calls.  This program was originally compiled     *
  9. * with Microsoft C 6.0 medium model and linked with Fastgraph          *
  10. * version 2.10.                                                        *
  11. *                                                                      *
  12. * For more information about Fastgraph, contact The Programmer's Shop. *
  13. *                                                                      *
  14. \**********************************************************************/
  15.  
  16. /**********************************************************************\
  17. *                                                                      *
  18. * To rebuild PROGSHOP.EXE:                                             *
  19. *                                                                      *
  20. * Let MSC create the header file containing the function prototypes:   *
  21. * cl /Zg progshop.c > progshop.h                                       *
  22. *                                                                      *
  23. * Compile and link with Fastgraph:                                     *
  24. * cl /c /W3 /AM progshop.c                                             *
  25. * link /E progshop,progshop.exe,NUL.MAP,fgm;                           *
  26. *                                                                      *
  27. \**********************************************************************/
  28.  
  29. #include "progshop.h"
  30.  
  31. #include <stdio.h>
  32. #include <stdlib.h>
  33. #include <string.h>
  34. #include <fastgraf.h>
  35.  
  36. #define FALSE 0
  37. #define TRUE  1
  38.  
  39. #define ESC     27
  40. #define SPACE   32
  41. #define ENTER   13
  42. #define INS     82
  43. #define ZERO    48
  44.  
  45. int hidden;
  46. int visual;
  47. int clockspeed;
  48. int seed;
  49. int old_mode;
  50.  
  51. int total;
  52. int ncoins;
  53. int npulls;
  54. int num[3];
  55. int bar0,bar1,bar2;
  56. int sym_0[3];
  57. int sym_1[3];
  58. int sym_2[3];
  59. int jackpot = FALSE;
  60. char triple_bar[76];
  61.  
  62. int reel0[] = {4,5,3,0,4,
  63.                5,6,5,4,5,
  64.                1,5,6,5,3,
  65.                5,2,5,4,5};
  66.  
  67. int reel1[] = {4,1,6,3,6,
  68.                0,5,6,2,6,
  69.                4,6,1,3,6,
  70.                2,6,5,2,6};
  71.  
  72. int reel2[] = {3,4,5,4,3,
  73.                4,3,0,4,3,
  74.                5,3,1,4,3,
  75.                4,3,2,3,4};
  76.  
  77.  
  78. int tri_x[] = {215,247,279,
  79.                215,247,279,
  80.                215,247,279,
  81.                318,382,350,
  82.                318,382};
  83.  
  84. int tri_y[] = {75,75,75,
  85.                97,97,97,
  86.                53,53,53,
  87.                53,97,75,
  88.                97,53};
  89.  
  90. /**********************************************************************\
  91. *                                                                      *
  92. *                                 main                                 *
  93. *                                                                      *
  94. \**********************************************************************/
  95.  
  96. int colors[] = {0,1,16,3,4,5,38,7,56,6,2,32,52,59,62,63};
  97.  
  98. void main()
  99. {
  100.    unsigned char key, aux;
  101.  
  102.    if (fg_egacheck() != 4) 
  103.    {
  104.       printf("\n");
  105.       printf("This program requires an EGA with 256K \n");
  106.       printf("and an Enhanced Color Display (ECD).\n\n");
  107.       printf("If an EGA is present, it must be the active adapter.\n");
  108.       exit(0);
  109.    }
  110.  
  111.    init_graphics(16);
  112.  
  113.    fg_palettes(colors);
  114.    fg_setpage(hidden);
  115.    fg_move(0,349);
  116.    fg_dispfile("progshp0.ppr",640,1);
  117.    fg_copypage(hidden,visual);
  118.  
  119.    fg_setpage(hidden);
  120.    fg_move(0,349);
  121.    fg_dispfile("progshp1.ppr",640,1);
  122.  
  123.    fg_setcolor(0);
  124.    fg_rect(340,380,146,150);
  125.    fg_rect(340,380,166,170);
  126.    fg_rect(340,380,186,190);
  127.  
  128.    /* wait for a key press to get past the intro screen */
  129.  
  130.    fg_getkey(&key,&aux);
  131.  
  132.    /* draw the background and the floor */
  133.  
  134.    fg_setpage(visual);
  135.    fg_setcolor(1);
  136.    fg_rect(0,639,0,349);
  137.    fg_setcolor(4);
  138.    fg_rect(0,639,292,349);
  139.    fg_setcolor(0);
  140.    fg_rect(0,639,291,291);
  141.  
  142.    /* copy the slot machine and the girl to the visual page */
  143.  
  144.    fg_palette(13,61);
  145.    fg_transfer(144,487,0,349,144,349,hidden,visual);
  146.    fg_transfer(488,639,0,259,456,349,hidden,visual);
  147.    fg_tcmask(2);
  148.  
  149.    /* pick up the triple bar bitmap */
  150.  
  151.    get_triple_bar();
  152.  
  153.    fg_setpage(hidden);
  154.    fg_move(tri_x[10],tri_y[10]);
  155.    fg_drawmap(triple_bar,4,19);
  156.  
  157.    npulls = 0;
  158.    spin_reels();
  159. }
  160.  
  161. /**********************************************************************\
  162. *                                                                      *
  163. *  clear_triple_bars -- unhighlight the bars at top of machine         *
  164. *                                                                      *
  165. \**********************************************************************/
  166.  
  167. void clear_triple_bars()
  168. {
  169.    register int i;
  170.    int x,y;
  171.  
  172.    fg_setpage(visual);
  173.    for (i = 0; i < 14; i++)
  174.    {
  175.       x = tri_x[i];
  176.       y = tri_y[i];
  177.  
  178.       fg_move(x,y);
  179.       fg_setcolor(0);
  180.       fg_drawmap(triple_bar,4,19); 
  181.       fg_setcolor(4);
  182.       fg_rect(x+10,x+11,y-13,y);
  183.       if (i == 10)
  184.       {
  185.          fg_setpage(hidden);
  186.          fg_move(x,y);
  187.          fg_setcolor(0);
  188.          fg_drawmap(triple_bar,4,19);
  189.          fg_setcolor(4);
  190.          fg_rect(x+10,x+11,y-13,y);
  191.          fg_setpage(visual);
  192.       }
  193.    }
  194. }
  195.  
  196. /**********************************************************************\
  197. *                                                                      *
  198. *  final_message -- say goodbye, Bertha                                *
  199. *                                                                      *
  200. \**********************************************************************/
  201.  
  202. char *exit_text[] = {
  203. "■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■",
  204. "                                                                                ",
  205. "                                                                                ",
  206. "                                                                                ",
  207. "        ┌─────────────────────────────────────────────────────────────┐         ",
  208. "        │                                                             │         ",
  209. "        │   Don't gamble with programming tools!  For all your        │         ",
  210. "        │   programming needs, including Fastgraph from Ted Gruber    │         ",
  211. "        │   Software, contact The Programmer's Shop.                  │         ",
  212. "        │                                                             │         ",
  213. "        │                   The Programmer's Shop                     │         ",
  214. "        │                   90 Industrial Park Road                   │         ",
  215. "        │                   Hingham, MA 02043                         │         ",
  216. "        │                   1-800-421-8006                            │         ",
  217. "        │                                                             │         ",
  218. "        │      This copy of Bertha Slot not for redistribution.       │         ",
  219. "        └─────────────────────────────────────────────────────────────┘         ",
  220. "                                                                                ",
  221. "                                                                                ",
  222. "                                                                                ",
  223. "■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■"
  224. };
  225. void final_message()
  226. {
  227.    register int i;
  228.    int row;
  229.  
  230.    fg_setattr(15,1,0);
  231.  
  232.    for (i = 0; i < 21; i++)
  233.    {
  234.       fg_locate(i,0);
  235.       fg_text(exit_text[i],80);
  236.    }
  237.  
  238.    /* lights at top and bottom */
  239.  
  240.    fg_locate(0,0);
  241.    for (i = 0; i < 80; i+=5)
  242.    {
  243.       fg_setattr(2,1,0);
  244.       fg_chgattr(1);
  245.       fg_setattr(3,1,0);
  246.       fg_chgattr(1);
  247.       fg_setattr(10,1,0);
  248.       fg_chgattr(1);
  249.       fg_setattr(11,1,1);
  250.       fg_chgattr(1);
  251.       fg_setattr(9,1,0);
  252.       fg_chgattr(1);
  253.    }
  254.    fg_locate(20,0);
  255.    for (i = 0; i < 80; i+=5)
  256.    {
  257.       fg_setattr(9,1,0);
  258.       fg_chgattr(1);
  259.       fg_setattr(11,1,1);
  260.       fg_chgattr(1);
  261.       fg_setattr(10,1,0);
  262.       fg_chgattr(1);
  263.       fg_setattr(3,1,0);
  264.       fg_chgattr(1);
  265.       fg_setattr(2,1,0);
  266.       fg_chgattr(1);
  267.    }
  268.  
  269.    fg_setattr(1,7,0);
  270.    for (row = 5; row <= 9; row++)
  271.    {
  272.       fg_locate(row,7);
  273.       fg_chgattr(65);
  274.    }
  275.    fg_locate(15,7);
  276.    fg_chgattr(65);
  277.  
  278.    fg_setattr(0,7,0);
  279.    for (row = 10; row <= 14; row++)
  280.    {
  281.       fg_locate(row,7);
  282.       fg_chgattr(65);
  283.    }
  284.  
  285.    /* red outline */
  286.  
  287.    fg_setattr(4,7,0);
  288.    fg_locate(4,7);
  289.    fg_chgattr(65);
  290.  
  291.    fg_locate(16,7);
  292.    fg_chgattr(65);
  293.  
  294.    for (row = 5; row <= 15; row++)
  295.    {
  296.       fg_locate(row,8);
  297.       fg_chgattr(1);
  298.       fg_locate(row,70);
  299.       fg_chgattr(1);
  300.    }
  301.  
  302.    /* 'Don't Gamble' */
  303.  
  304.    fg_setattr(4,7,0);
  305.    fg_locate(6,12);
  306.    fg_chgattr(36);
  307.  
  308.    /* The Programmer's Shop */
  309.  
  310.    fg_setattr(10,7,0);
  311.    fg_locate(8,30);
  312.    fg_chgattr(22);
  313.  
  314.    /* Fastgraph */
  315.  
  316.    fg_setattr(14,7,0);
  317.    fg_locate(7,41);
  318.    fg_chgattr(9);
  319.  
  320.    fg_locate(21,0);
  321.    return;
  322. }
  323.  
  324. /**********************************************************************\
  325. *                                                                      *
  326. *  flushkey -- flush out the keystroke buffer                          *
  327. *                                                                      *
  328. \**********************************************************************/
  329.  
  330. void flushkey()
  331. {
  332.   unsigned char key,aux;
  333.  
  334.   do
  335.      fg_intkey(&key,&aux);
  336.   while (key+aux > 0);
  337. }
  338.  
  339. /**********************************************************************\
  340. *                                                                      *
  341. *  getseed -- get a seed for the random number generator               *
  342. *                                                                      *
  343. \**********************************************************************/
  344.  
  345. void getseed()
  346. {
  347.    seed = (int)(fg_getclock() & 0x7FFF);
  348. }
  349.  
  350. /**********************************************************************\
  351. *                                                                      *
  352. *  get_string_x -- return position of number string                    *
  353. *                                                                      *
  354. \**********************************************************************/
  355.  
  356. get_string_x(num)
  357. int num;
  358. {
  359.    if (num < 0)
  360.    {
  361.       if (num <= -10000)
  362.          return(340);
  363.       else if (num <= -1000)
  364.          return(343);
  365.       else if (num <= -100)
  366.          return(347);
  367.       else if (num <= -10)
  368.          return(351);
  369.       else
  370.          return(354);
  371.    }
  372.    else if (num < 10) 
  373.       return(358);
  374.    else if (num < 100) 
  375.       return(354);
  376.    else if (num < 1000) 
  377.       return(351);
  378.    else if (num < 10000)
  379.       return(347);
  380.    else
  381.       return(343);
  382. }
  383.  
  384. /**********************************************************************\
  385. *                                                                      *
  386. *  getsym -- return the nth symbol on reel i                           *
  387. *                                                                      *
  388. \**********************************************************************/
  389.  
  390. getsym(i,n)
  391. int i,n;
  392. {
  393.    register int sym;
  394.  
  395.    switch(i)
  396.    {
  397.       case 0:
  398.          sym = reel0[n];
  399.          break;
  400.       case 1:
  401.          sym = reel1[n];
  402.          break;
  403.       case 2:
  404.          sym = reel2[n];
  405.          break;
  406.    }
  407.    return(sym);
  408. }
  409.  
  410. /**********************************************************************\
  411. *                                                                      *
  412. *  get_triple_bar -- pick up a bitmap of Prog Shop logo                *
  413. *                                                                      *
  414. \**********************************************************************/
  415.  
  416. void get_triple_bar()
  417. {
  418.    fg_setpage(hidden);
  419.    fg_setcolor(0);
  420.    fg_move(306,148);
  421.    fg_getmap(triple_bar,4,19);
  422. }
  423.  
  424. /**********************************************************************\
  425. *                                                                      *
  426. *  init_graphics -- initialize the graphics environment                *
  427. *                                                                      *
  428. \**********************************************************************/
  429.  
  430. void init_graphics(mode)
  431. int mode;
  432. {
  433.    /* find out what the old video mode is */
  434.  
  435.    old_mode = fg_getmode();
  436.  
  437.    /* initialize the new video mode */
  438.  
  439.    fg_setmode(mode);
  440.  
  441.    /* set up visual and hidden pages */
  442.  
  443.    fg_setpage(0);
  444.    fg_setvpage(0);
  445.    fg_sethpage(1);
  446.    visual = 0;
  447.    hidden = 1;   
  448.  
  449.    getseed();
  450.    clockspeed = fg_measure();
  451.  
  452.    /* turn off the numlock key */
  453.  
  454.    fg_setnum(0);
  455. }
  456.  
  457. /**********************************************************************\
  458. *                                                                      *
  459. *  insert_sound -- noise when coins are inserted                       *
  460. *                                                                      *
  461. \**********************************************************************/
  462.  
  463. void insert_sound()
  464. {
  465.    if (!fg_numlock())
  466.    {
  467.       fg_waitfor(1);
  468.       fg_sound(900,1);
  469.    }
  470. }
  471.  
  472. /**********************************************************************\
  473. *                                                                      *
  474. *  irandom -- generate a random number                                 *
  475. *                                                                      *
  476. \**********************************************************************/
  477.  
  478. irandom(min,max)
  479. int min;
  480. int max;
  481. {
  482.    register int temp;
  483.  
  484.    temp = seed ^ (seed >> 7);
  485.    seed = ((temp << 8) ^ temp) & 0x7FFF;
  486.    return((seed % (max-min+1)) + min);
  487. }
  488.  
  489. /**********************************************************************\
  490. *                                                                      *
  491. *  payout -- calculate return the payout on one of 5 lines             *
  492. *                                                                      *
  493. \**********************************************************************/
  494.  
  495. payout(j)
  496. int j;
  497.  
  498.    /*  0 <= num[i] <= 19 is top position on ith reel */
  499.  
  500. {
  501.    int sym0,sym1,sym2;
  502.    int amount;
  503.  
  504.    bar0 = FALSE;
  505.    bar1 = FALSE;
  506.    bar2 = FALSE;
  507.  
  508.    switch(j)
  509.    {
  510.       case 1:
  511.          sym0 = sym_1[0];
  512.          sym1 = sym_1[1];
  513.          sym2 = sym_1[2];
  514.          break;
  515.       case 2:
  516.          sym0 = sym_2[0];
  517.          sym1 = sym_2[1];
  518.          sym2 = sym_2[2];
  519.          break;
  520.       case 3:
  521.          sym0 = sym_0[0];
  522.          sym1 = sym_0[1];
  523.          sym2 = sym_0[2];
  524.          break;
  525.       case 4:
  526.          sym0 = sym_0[0];
  527.          sym1 = sym_1[1];
  528.          sym2 = sym_2[2];
  529.          break;
  530.       case 5:
  531.          sym0 = sym_2[0];
  532.          sym1 = sym_1[1];
  533.          sym2 = sym_0[2];
  534.          break;
  535.    }
  536.  
  537.    if (j == 5 && sym0 == 0 && sym1 == 0 && sym2 == 0)
  538.       return(2000);
  539.  
  540.    if (sym0 == 0 || sym0 == 1 || sym0 == 2) bar0 = TRUE;
  541.    if (sym1 == 0 || sym1 == 1 || sym1 == 2) bar1 = TRUE;
  542.    if (sym2 == 0 || sym2 == 1 || sym2 == 2) bar2 = TRUE;
  543.  
  544.    amount = 0;
  545.  
  546.    /* three symbols match */
  547.  
  548.    if (sym0 == sym1 && sym1 == sym2)
  549.    {
  550.       switch(sym0)
  551.       {                    
  552.          case 0:             /* 3 bar */
  553.             amount = 200;
  554.             jackpot = TRUE;
  555.             break;
  556.          case 1:             /* 2 bar */
  557.             amount = 100;
  558.             jackpot = TRUE;
  559.             break;
  560.          case 2:             /* 1 bar */
  561.             amount = 50;
  562.             jackpot = TRUE;
  563.             break;
  564.          case 3:             /* bells */
  565.             amount = 18;
  566.             break;
  567.          case 4:             /* plums */
  568.             amount = 14;
  569.             break;
  570.          case 5:             /* oranges */
  571.             amount = 10;
  572.             break;
  573.       }
  574.    }
  575.  
  576.    /* any bars */
  577.  
  578.    else if (bar0 && bar1 && bar2) 
  579.    {
  580.           amount = 20;
  581.           jackpot = TRUE;
  582.    }
  583.    /* 2 bells and 1 bar */
  584.  
  585.    else if (sym0 == 3 && sym1 == 3 && bar2)
  586.           amount = 18;
  587.  
  588.    /* 2 plums and 1 bar */
  589.  
  590.    else if (sym0 == 4 && sym1 == 4 && bar2)
  591.           amount = 14;
  592.  
  593.    /* 2 oranges and 1 bar */
  594.  
  595.    else if (sym0 == 5 && sym1 == 5 && bar2)
  596.           amount = 10;
  597.  
  598.    /* 2 cherries */
  599.  
  600.    else if (sym0 == 6 && sym1 == 6)
  601.           amount = 5;
  602.  
  603.    /* 1 cherry */
  604.  
  605.    else if (sym0 == 6)
  606.           amount = 2;
  607.  
  608.    return(amount);
  609. }
  610.  
  611. /**********************************************************************\
  612. *                                                                      *
  613. *  payout_sound -- noise for coin payout  ("dink! dink! dink")         *
  614. *                                                                      *
  615. \**********************************************************************/
  616.  
  617. void payout_sound()
  618. {
  619.    fg_waitfor(1);
  620.  
  621.    if (!fg_numlock())
  622.       fg_sound(1500,1);
  623. }
  624.  
  625. /**********************************************************************\
  626. *                                                                      *
  627. *  put_string -- put 5X5 bitmapped text at an x,y position             *
  628. *                                                                      *
  629. \**********************************************************************/
  630.  
  631. char chars[41][5] = {
  632. -120,  -8,-120,  80,  32,  /* A */
  633.  -16,-120, -16,-120, -16,  /* B */
  634.  120,-128,-128,-128, 120,  /* C */
  635.  -16,-120,-120,-120, -16,  /* D */
  636.   -8,-128, -16,-128,  -8,  /* E */
  637. -128,-128, -16,-128, -16,  /* F */
  638.  112,-120,-104,-128, 120,  /* G */
  639. -120,-120,  -8,-120,-120,  /* H */
  640.  112,  32,  32,  32, 112,  /* I */
  641.   96,-112,  16,  16,  56,  /* J */
  642. -120,-112, -32,-112,-120,  /* K */
  643.   -8,-128,-128,-128,-128,  /* L */
  644. -120, -88, -88, -40,-120,  /* M */
  645. -120,-104, -88, -56,-120,  /* N */
  646.  112,-120,-120,-120, 112,  /* O */
  647. -128,-128, -16,-120, -16,  /* P */
  648.  120, -88,-120,-120, 112,  /* Q */
  649. -112, -96, -16,-120, -16,  /* R */
  650.  -16,   8, 112,-128, 120,  /* S */
  651.   32,  32,  32,  32,  -8,  /* T */
  652.  112,-120,-120,-120,-120,  /* U */
  653.   32,  80,-120,-120,-120,  /* V */
  654. -120, -40, -88, -88,-120,  /* W */
  655. -120,  80,  32,  80,-120,  /* X */
  656.   32,  32,  32,  80,-120,  /* Y */
  657.   -8,  64,  32,  16,  -8,  /* Z */
  658.  112,-120,-120,-120, 112,  /* O */
  659.  112,  32,  32,  96,  32,  /* 1 */
  660.  -16,  64,  32,-112,  96,  /* 2 */
  661.  -32,  16,  96,  16, -32,  /* 3 */
  662.   16,  16, -16,-112,-112,  /* 4 */
  663.  112,   8, -16,-128,  -8,  /* 5 */
  664.  112,-120, -16,-128, 112,  /* 6 */
  665.   64,  64,  32,  16,  -8,  /* 7 */
  666.  112,-120, 112,-120, 112,  /* 8 */
  667.   16,   8, 120,-120, 112,  /* 9 */
  668.  128,  64,   0,   0,   0,  /* , */
  669.   64,   0,   0,   0,   0,  /* . */
  670.    0,   0, 112,   0,   0,  /* - */
  671.   64,   0,   0,  64,   0}; /* : */
  672.  
  673. void put_string(string,x,y,space)
  674. char string[];
  675. int x;
  676. int y;
  677. int space;
  678. {
  679.    register int i, nchar;
  680.    int blank;
  681.    char ch;
  682.    
  683.    nchar = strlen(string);
  684.  
  685.    for (i = 0; i < nchar; i++)
  686.    {
  687.       blank = FALSE;
  688.       ch = string[i];
  689.       if (ch >= 65 && ch <= 90)       /* upper case */
  690.          ch -= 65;
  691.       else if (ch >= 97 && ch <= 122) /* lower case */
  692.          ch -= 97;   
  693.       else if (ch >= 48 && ch <= 57)  /* numbers */
  694.          ch -= 22;
  695.       else if (ch == 44)              /* comma */
  696.          ch = 36;
  697.       else if (ch == 46)              /* period */
  698.          ch = 37;
  699.       else if (ch == 45)              /* minus */
  700.          ch = 38;
  701.       else if (ch == 58)              /* colon */
  702.          ch = 39;
  703.       else 
  704.          blank = TRUE;
  705.  
  706.       fg_move(x,y);
  707.       if (!blank) fg_drawmap(&chars[ch][0],1,5);
  708.       x += space;
  709.    }
  710. }
  711.  
  712. /**********************************************************************\
  713. *                                                                      *
  714. *  put_triple_bars -- highlight bars at top as coins are inserted      *
  715. *                                                                      *
  716. \**********************************************************************/
  717.  
  718. void put_triple_bars(ncoins)
  719. int ncoins;
  720. {
  721.    register int i;
  722.    int i1,i2;
  723.    int x,y;
  724.  
  725.    switch(ncoins)
  726.    {
  727.       case(1):
  728.          i1 = 0;
  729.          i2 = 2;
  730.          break;
  731.       case(2):
  732.          i1 = 3;
  733.          i2 = 5;
  734.          break;
  735.       case(3):
  736.          i1 = 6;
  737.          i2 = 8;
  738.          break;
  739.       case(4):
  740.          i1 = 9;
  741.          i2 = 11;
  742.          break;
  743.       case(5):
  744.          i1 = 0;
  745.          i2 = 13;
  746.          break;
  747.    }
  748.  
  749.    for (i = i1; i <= i2; i++)
  750.    {
  751.       x = tri_x[i];
  752.       y = tri_y[i];
  753.  
  754.       fg_move(x,y);
  755.       fg_setcolor(8);
  756.       fg_drawmap(triple_bar,4,19); 
  757.       fg_setcolor(12);
  758.       fg_rect(x+10,x+11,y-13,y);
  759.  
  760.       if (i == 10)
  761.       {
  762.          fg_setpage(hidden);
  763.          fg_move(x,y);
  764.          fg_setcolor(8);
  765.          fg_drawmap(triple_bar,4,19); 
  766.  
  767.          fg_setcolor(12);
  768.          fg_rect(x+10,x+11,y-13,y);
  769.  
  770.          fg_setpage(visual);
  771.       }
  772.    }
  773. }
  774.  
  775. /**********************************************************************\
  776. *                                                                      *
  777. *  quit_graphics -- return the computer to its original state          *
  778. *                                                                      *
  779. \**********************************************************************/
  780.  
  781. void quit_graphics()
  782. {
  783.    /* make sure the speaker is off */
  784.  
  785.    fg_hush();
  786.  
  787.    /* set the mode to whatever it was originally */
  788.  
  789.    fg_setmode(old_mode);
  790.    fg_reset();
  791.  
  792.    final_message();
  793.  
  794.    exit(0);
  795. }
  796.  
  797. /**********************************************************************\
  798. *                                                                      *
  799. *  random_song -- play a nice song while the reels are spinning        *
  800. *                                                                      *
  801. \**********************************************************************/
  802.  
  803. void random_song(i)
  804. int i;
  805. {
  806.    switch(i)
  807.    {
  808.       case(0):
  809.          fg_musicb("O4 T130 L16 BA L8 G L16 GAGD O- B O+ CDED O- B O+ L8 D L16 GA L8 BB L16 BAGA L8 BAA$",1);
  810.          break;
  811.       case(1):
  812.          fg_musicb("O4 T120 L8 D L16 GBAG L8 EEDD G. L16 P L8 AABB L16 ABAG L8 ED$",1);
  813.          break;
  814.       case(2):
  815.          fg_musicb("O4 T240 L8 DE L4 F#F#D L8 DE L4 F#F#D L8 DE L8 F#F#F#F#GGF#F# L2 E $",1);
  816.          break;
  817.       case(3):
  818.          fg_musicb("O4 T160 L4 AAA. L16 G#. L32 A L8 A#AG#AFCFA L4 O+ CCC. L16 O- B O+ C L8 DC O- L16 BB O+ L8 C O- ACDF$",1);
  819.          break;
  820.       case(4):
  821.          fg_musicb("O4 T140 L8 EEC#EF#EC#PC# L4O-BO+ L8PC# L4O-BO+L8EEEC#EF#EC#P L4O-BO+L8C#O-BO+ L4O-A$",1);
  822.          break;
  823.       case(5):
  824.          fg_musicb("O4 T250 L4 O- G L4 G O+ CD L2 E L8 EE L4 F O- AA O+ L2 D O- L4 GGB O+ C L4 DE. L8 D L4 DC O- A L2 G$",1);
  825.          break;
  826.    }
  827. }
  828.  
  829. /**********************************************************************\
  830. *                                                                      *
  831. * spin_reels -- pull the handle and watch the reels go around          *
  832. *                                                                      *
  833. \**********************************************************************/
  834.  
  835. void spin_reels()
  836. {
  837.    register int i,j;
  838.    unsigned char key,aux;
  839.    int skip;
  840.    int stall_time;
  841.    int sym;
  842.    int bottom[3];
  843.    int top[3];
  844.    int reel_num = 0;
  845.    int x,y;
  846.    int win_amount;
  847.    int counter[3];
  848.    char string[7];
  849.    int face_count;
  850.    int face_target;
  851.    int hip_count;
  852.    int hip_target;
  853.  
  854.    static int old_song = 0;
  855.    int song_no;
  856.  
  857.    static int stop[] = {0,0,0};
  858.    static int stopped[] = {0,0,0};
  859.  
  860.    static int xmin[] = {208,256,304};
  861.    static int xmax[] = {239,287,335};
  862.    static int ymin = 129;
  863.    static int ymax = 200;
  864.    static int even = TRUE;
  865.  
  866.    static int x1[] = {208,208,304,304,256,208,256};
  867.    static int x2[] = {239,239,335,335,287,239,287};
  868.    static int y1[] = {177,129,177,153,129,153,177};
  869.    static int y2[] = {200,152,200,176,152,176,200};
  870.    static int siren[] = {750,1,700,1,650,1,600,1,550,1,500,1,450,1,400,1,
  871.                          450,1,500,1,550,1,600,1,650,1,700,0,0};
  872.    static int handle[] = {420,5,415,4,410,3,400,2,390,1,
  873.                           380,1,370,1,360,1,350,1,340,1,330,1,
  874.                           320,1,310,1,300,1,290,1,280,1,270,1,
  875.                           320,1,350,1,380,1,420,1,450,1,500,1,
  876.                           550,1,0,0};
  877.  
  878.    stall_time = clockspeed/8;
  879.  
  880.    fg_setpage(visual);
  881.    fg_setcolor(15);
  882.  
  883.    for (i = 0; i < 3; i++)
  884.    {
  885.       num[i] = 0;
  886.       bottom[i] = y2[getsym(i,0)];
  887.    }
  888.  
  889.    while(1)
  890.    {
  891.  
  892.       /* initialize stuff for the spin */
  893.  
  894.       for (i = 0; i<3; i++)
  895.       {
  896.          stop[i] = FALSE;
  897.          stopped[i] = FALSE;
  898.       }
  899.  
  900.       skip = 8;
  901.       reel_num = 0;
  902.       clear_triple_bars();
  903.  
  904.       /* get coins */
  905.  
  906.       ncoins = 0;
  907.       key = 0;
  908.       face_count = 0;
  909.       face_target = irandom(50,200);
  910.       hip_count = 0;
  911.       hip_target = irandom(50,100);
  912.  
  913.       while (key != ENTER && ncoins < 5)
  914.       {
  915.          while(1)
  916.          {
  917.             fg_waitfor(2);
  918.             fg_intkey(&key,&aux);
  919.             if (key+aux > 0) break;
  920.  
  921.             /* make kissy-faces */
  922.  
  923.             face_count++;
  924.             if (face_count == face_target)
  925.             {
  926.                fg_transfer(488,543,261,307,528,137,hidden,visual);
  927.             }
  928.             else if (face_count >= face_target+2)
  929.             {
  930.                fg_transfer(560,615,1,47,528,137,hidden,visual);
  931.                face_count = 0;
  932.                face_target = irandom(100,300);
  933.             }
  934.  
  935.             /* swish the hips */
  936.  
  937.             hip_count++;
  938.             if (hip_count == hip_target)
  939.                fg_transfer(544,607,260,349,528,279,hidden,visual);
  940.             else if (hip_count == hip_target+2 && hip_target > 150)
  941.                fg_transfer(488,639,0,259,456,349,hidden,visual);
  942.             else if (hip_count == hip_target+4 && hip_target > 150)
  943.                fg_transfer(544,607,260,349,528,279,hidden,visual);
  944.             else if (hip_count >= hip_target+6)
  945.             {
  946.                fg_transfer(488,639,0,259,456,349,hidden,visual);
  947.                hip_target = irandom(5,300);
  948.                hip_count = 0;
  949.             }
  950.          }
  951.  
  952.          if (key == ESC) 
  953.             quit_graphics();
  954.  
  955.          else if (key == SPACE)
  956.          {
  957.             insert_sound();
  958.             ncoins++;
  959.             sprintf(string,"%-6d\0",ncoins);
  960.             fg_setcolor(4);
  961.             fg_rect(428,432,58,62);
  962.             fg_setcolor(14);
  963.             put_string(string,428,62,7);
  964.    
  965.             /* record total */
  966.       
  967.             total--;
  968.             x = get_string_x(total);
  969.             sprintf(string,"%-6d\0",total);
  970.             fg_setcolor(0);
  971.             fg_rect(340,380,166,170);
  972.             fg_setcolor(14);
  973.             put_string(string,x,170,7);
  974.             if (ncoins == 1) clear_triple_bars();
  975.             put_triple_bars(ncoins);
  976.          }
  977.  
  978.          /* insert key for 5 coins */
  979.  
  980.          else if (key == ZERO || aux == INS)
  981.          {
  982.             ncoins = 5;
  983.             sprintf(string,"%-6d\0",ncoins);
  984.             fg_setcolor(4);
  985.             fg_rect(428,432,58,62);
  986.             fg_setcolor(14);
  987.             put_string(string,428,62,7);
  988.       
  989.             /* record total */
  990.          
  991.             total -= 5;
  992.             x = get_string_x(total);
  993.             sprintf(string,"%-6d\0",total);
  994.             fg_setcolor(0);
  995.             fg_rect(340,380,166,170);
  996.             fg_setcolor(14);
  997.             put_string(string,x,170,7);
  998.             put_triple_bars(5);
  999.             break;
  1000.          }
  1001.       }
  1002.  
  1003.       /* must play at least one coin */
  1004.  
  1005.       if (ncoins == 0)
  1006.       {
  1007.          insert_sound();
  1008.          ncoins = 1;
  1009.          sprintf(string,"%-6d\0",ncoins);
  1010.          fg_setcolor(4);
  1011.          fg_rect(428,432,58,62);
  1012.          fg_setcolor(14);
  1013.          put_string(string,428,62,7);
  1014.  
  1015.          /* record total */
  1016.  
  1017.          total--;
  1018.          x = get_string_x(total);
  1019.          sprintf(string,"%-6d\0",total);
  1020.          fg_setcolor(0);
  1021.          fg_rect(340,380,166,170);
  1022.          fg_setcolor(14);
  1023.          put_string(string,x,170,7);
  1024.          put_triple_bars(ncoins);
  1025.       }
  1026.  
  1027.       /* clear the "you win" row */
  1028.  
  1029.       fg_setcolor(0);
  1030.       fg_rect(340,380,146,150);
  1031.  
  1032.       if (!fg_numlock()) fg_sounds(handle,1);
  1033.  
  1034.       /* restore girl's face */
  1035.  
  1036.       fg_transfer(560,615,1,47,528,137,hidden,visual);
  1037.  
  1038.       /* pull the handle */
  1039.  
  1040.       fg_setpage(hidden);
  1041.       fg_setcolor(1);
  1042.       fg_rect(0,143,263,393);
  1043.       fg_setpage(visual);
  1044.       fg_transfer(400,487,90,220,0,393,hidden,hidden);
  1045.       fg_tcxfer(0,111,0,129,32,393,hidden,hidden);
  1046.       fg_transfer(0,143,263,393,400,220,hidden,visual);
  1047.  
  1048.       fg_waitfor(1);
  1049.  
  1050.       fg_setpage(hidden);
  1051.       fg_setcolor(1);
  1052.       fg_rect(0,143,263,393);
  1053.       fg_setpage(visual);
  1054.       fg_transfer(400,487,90,220,0,393,hidden,hidden);
  1055.       fg_tcxfer(0,143,131,261,0,393,hidden,hidden);
  1056.       fg_transfer(0,143,263,393,400,220,hidden,visual);
  1057.  
  1058.       fg_waitfor(2);
  1059.  
  1060.       fg_transfer(400,487,64,349,400,349,hidden,visual);
  1061.       fg_transfer(488,639,0,259,456,349,hidden,visual);
  1062.  
  1063.       while (fg_playing()) fg_waitfor(1);
  1064.  
  1065.       /* spin the three reels */
  1066.  
  1067.       do
  1068.          song_no = irandom(0,5);
  1069.       while (song_no == old_song);
  1070.  
  1071.       if (song_no < 3)
  1072.       {
  1073.          counter[0] = irandom(30,60);
  1074.          counter[1] = counter[0] + irandom(30,60);
  1075.          counter[2] = counter[1] + irandom(30,60);
  1076.       }
  1077.       else
  1078.       {
  1079.          counter[0] = irandom(60,90);
  1080.          counter[1] = counter[0] + irandom(60,90);
  1081.          counter[2] = counter[1] + irandom(60,90);
  1082.       }
  1083.  
  1084.       if (!fg_numlock()) random_song(song_no);
  1085.       old_song = song_no;
  1086.  
  1087.       while(1)
  1088.       {
  1089.          flushkey();
  1090.          for (i = 0; i < 3; i++)
  1091.          {
  1092.             fg_stall(stall_time);
  1093.  
  1094.             if (counter[i] > 0) 
  1095.                counter[i]--;
  1096.             else
  1097.                stop[i] = TRUE;
  1098.  
  1099.             if (!stopped[i])
  1100.             {
  1101.                sym = getsym(i,num[i]);
  1102.                bottom[i] = bottom[i] - skip;
  1103.                if (bottom[i] <= y1[sym])
  1104.                {
  1105.                   /* stop the reel at the bottom of a symbol */
  1106.  
  1107.                   if (stop[i]) 
  1108.                   {
  1109.                      stopped[i] = TRUE;
  1110.                      sym_0[i] = sym;
  1111.    
  1112.                      /* get the 2nd and third symbol on the reel */
  1113.    
  1114.                      j = num[i] - 1;
  1115.                      if (j < 0) j = 19;
  1116.                      sym_1[i] = getsym(i,j);
  1117.                      j --;
  1118.                      if (j < 0) j = 19;
  1119.                      sym_2[i] = getsym(i,j);
  1120.                   }           
  1121.    
  1122.                   /* or else get the next symbol on the reel */
  1123.    
  1124.                   else 
  1125.                   {
  1126.    
  1127.                      num[i]++;
  1128.                      if (num[i] >= 20) num[i] = 0;
  1129.                      sym = getsym(i,num[i]);
  1130.                      bottom[i] = y2[sym];
  1131.                   }
  1132.                }
  1133.             }
  1134.             top[i] = bottom[i] - skip + 1; 
  1135.             y = ymin + skip - 1;
  1136.    
  1137.             if (!stopped[i])
  1138.             {
  1139.                fg_setcolor(15);
  1140.                fg_scroll(xmin[i],xmax[i],ymin,ymax-skip,skip,1);
  1141.                fg_transfer(x1[sym],x2[sym],top[i],bottom[i],xmin[i],y,hidden,visual);
  1142.             }
  1143.          }
  1144.          if (stopped[0])
  1145.             skip = 6;
  1146.          else if (stopped[1])
  1147.             skip = 4;
  1148.          if (stopped[0] && stopped[1] && stopped [2]) 
  1149.          {
  1150.             flushkey();
  1151.             while (fg_playing()) fg_waitfor(1);
  1152.  
  1153.             /* record win amount */
  1154.  
  1155.             win_amount = 0;
  1156.             for (j = 1; j <= ncoins; j++)
  1157.                win_amount = win_amount + payout(j);
  1158.  
  1159.             if (win_amount == 0)
  1160.             {
  1161.                fg_setcolor(0);
  1162.                fg_rect(340,380,146,150);
  1163.                fg_setcolor(14);
  1164.                put_string("0",358,150,7);
  1165.             }
  1166.             else
  1167.             {
  1168.                if (jackpot && !fg_numlock()) fg_sounds(siren,-1);
  1169.                for (j = 1; j <= win_amount; j++)
  1170.                {
  1171.                   if (!jackpot) payout_sound();               
  1172.                   x = get_string_x(j);
  1173.                   sprintf(string,"%-6d\0",j);
  1174.                   fg_setcolor(0);
  1175.                   fg_rect(340,380,146,150);
  1176.                   fg_setcolor(14);
  1177.                   put_string(string,x,150,7);
  1178.  
  1179.                   /* record total */
  1180.  
  1181.                   total ++; 
  1182.                   x = get_string_x(total);
  1183.                   sprintf(string,"%-6d\0",total);
  1184.                   fg_setcolor(0);
  1185.                   fg_rect(340,380,166,170);
  1186.                   fg_setcolor(14);
  1187.                   put_string(string,x,170,7);
  1188.                   if (jackpot)
  1189.                   {
  1190.                      fg_waitfor(4);
  1191.                      if (even)
  1192.                         fg_palette(11,52);
  1193.                      else
  1194.                         fg_palette(11,32);
  1195.                      even = !even;
  1196.                   }
  1197.                }
  1198.             }
  1199.  
  1200.             /* record the number of pulls */
  1201.  
  1202.             npulls++;
  1203.             x = get_string_x(npulls);
  1204.             sprintf(string,"%-6d\0",npulls);
  1205.             fg_setcolor(0);
  1206.             fg_rect(340,380,186,190);
  1207.             fg_setcolor(14);
  1208.             put_string(string,x,190,7);
  1209.             fg_hush();
  1210.             jackpot = FALSE;
  1211.             even = TRUE;
  1212.             fg_palette(11,32);
  1213.             break;
  1214.          }
  1215.       }
  1216.    }
  1217. }
  1218.  
  1219.